what are classes, methods and objects in java?
Classes in Java A class in Java is a user-defined blueprint or prototype from which objects are created1. It’s a set of objects which share common characteristics/behavior and common properties/attributes1. For example, Student is a class, while a particular student named Ravi is an object1. A class can contain data members, methods, constructors, nested classes, and interfaces1. Here’s an example of a class declaration in Java:
Class
Class in Java
access_modifier class {
data member;
method;
constructor;
nested class;
interface;
}
Method
Methods in Java Methods in Java represent the behavior of an object1. They are used to perform operations. For example, in a Bicycle class, braking() could be a method2. Here’s an example of a method in Java:
Method in java
public void braking() {
System.out.println (""Working of Braking"");
}
Object
Objects in Java An object in Java is an instance of a class1. It’s a basic unit of Object-Oriented Programming and represents real-life entities1. For example, a particular student named Ravi is an object of the Student class1. An object consists of state (represented by attributes) and behavior (represented by methods)1. Here’s an example of creating an object in Java:
Object in java
className object = new className();
//For the Bicycle class, you could create an object like this:
Bicycle sportsBicycle = new Bicycle();
here Bicycle is the class and sportsBicycle is the object
lets discuss deeper in the upcoming posts